import type { App } from "vue";
import { createRouter, createWebHashHistory, RouteRecordRaw } from "vue-router";

// 静态路由
export const constantRoutes: RouteRecordRaw[] = [
  {
    path: '/',
    redirect: '/workSpace',
    meta: { hidden: true },
  },
  {
    path: '/workspace',
    redirect: '/home/view',
    meta: { title: '工作空间' },
    children: [
      {
        path: '/home/view',
        name: 'workSpace',
        component: () => import('@/views/workSpace/index.vue'),
        meta: { title: '工作台', requireAuth: true, affix: true, closable: false },
      },
    ]
  }
];

/**
 * 创建路由
 */
const router = createRouter({
  history: createWebHashHistory(),
  routes: constantRoutes,
  // 刷新时，滚动条位置还原
  scrollBehavior: () => ({ left: 0, top: 0 }),
});

// 全局注册 router
export function setupRouter(app: App<Element>) {
  app.use(router);
}

export default router;
